﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using CodingTheTweet;

namespace TwiXaml
{
	/// <summary>
	/// Interaction logic for Configure.xaml
	/// </summary>
	public partial class Configure : Window
	{
        private String link;
        oAuthTwitter oAuth = new oAuthTwitter();

		public Configure()
		{
			this.InitializeComponent();
            
            oAuth.ConsumerKey = Settings1.Default.consumerKey;
            oAuth.ConsumerSecret = Settings1.Default.consumerSecret;
            link = oAuth.AuthorizationLinkGet();
            System.Diagnostics.Process.Start(link);
			
		
		}

        private void authButton_Click(object sender, RoutedEventArgs e)
        {
            try{
                
              
            
                oAuth.AccessTokenGet(oAuth.OAuthToken, PinBox.Text.Trim());

                MessageBox.Show(this, "Success! You're ready to start tweeting!", "TwiXaml", MessageBoxButton.OK);
                
                Settings1.Default.token = oAuth.Token;
                Settings1.Default.authToken = oAuth.OAuthToken;
                Settings1.Default.secretToken = oAuth.TokenSecret;
                Settings1.Default.pin = oAuth.PIN;
                Settings1.Default.Save();
                this.Close();
                
            
            }

            
            
            catch (Exception ex)
            {
                MessageBox.Show(this, "An error occurred during authorization:\n\n" + ex.Message, "TwiXaml", MessageBoxButton.OK);
            }
        }
	}
}